


import { Ajax } from '@/api/api'
import React, { FC, useRef } from 'react'

const UploadFile:FC<any> = ({
    children,
    emitPath
}) => {
    const fileRef:any  = useRef()
    const todoUpLoad = async ()=>{
        const file = fileRef.current.files[0]
        const data = new FormData()
        data.append('file',file) 
        let res:any = await Ajax.uplodafile(data)
        if(res.code==200){
            emitPath(res.path)
        }
    }
    const startUpload = ()=>{
        fileRef.current.click()
    }
    return (
        <div onClick={startUpload}>
            <input type="file" ref={fileRef}  style={{display:'none'}}  onChange={todoUpLoad}   />
            {
                children
            }
        </div>
    )
}

export default UploadFile